<?php
// subscription prices page
//require_once 'view/adm/users/prices.index.php';
require_once WACT_ROOT . 'controller/controller.inc.php';
require_once WACT_ROOT . 'controller/form.inc.php';
require_once WACT_ROOT . 'validation/rules/match.inc.php';
require_once WACT_ROOT . 'validation/rules/member.inc.php';
require_once WACT_ROOT . 'validation/rules/pattern.inc.php';

require_once WACT_ROOT .'view/formview.inc.php';
require_once APP_ROOT . 'view/common/layout.formview.php';
require_once APP_ROOT . 'model/common/subscription.php';


class SubscriptionPrices extends PageController {

	var $form;

    function SubscriptionPrices() {
        parent::PageController();
        $this->form =& new FormController();
        $this->form->addChild('save', new ButtonController(new Delegate($this, 'save')));
        $this->form->setDefaultChild('save');


             $this->form->addRule(new Handle('RequiredRule', array('type1')));
             $this->form->addRule(new Handle('RequiredRule', array('type2')));
             $this->form->addRule(new Handle('RequiredRule', array('type3')));
             $this->form->addRule(new Handle('RequiredRule', array('type4')));  
             // TO DO: add numeric validation
             //$priceRule=& new PatternRule('type1','/^[0-9]{1,5}$/');
		     //$priceRule->setGroup('pricerule');
			 //$this->form->addRule($priceRule);



        $this->addChild('PricesForm', $this->form);
        $this->setDefaultChild('PricesForm');
        $this->setDefaultView(new Handle('LayoutFormView', array('/adm/users/prices.index.html')));

        $this->addView('success', WACT_DEFAULT_VIEW);

        $this->form->registerOnLoadListener(new Delegate($this, 'load'));
        //$this->registerOnActivateListener(new Delegate($this, 'guard'));

    }

    function load(&$source, &$request, &$responseModel) {
        Subscription::getPrices($responseModel);
        return 'success';
    }
    function save(&$source, &$request, &$responseModel) {
    	//print "saving";
    	$price1 = $request->getPostProperty('type1');
    	$price2 = $request->getPostProperty('type2');
    	$price3 = $request->getPostProperty('type3');
        $price4 = $request->getPostProperty('type4');


        Subscription::savePrice(1, $price1);
        Subscription::savePrice(2, $price2);
        Subscription::savePrice(3, $price3);
        Subscription::savePrice(4, $price4);
        return 'success';

    }
}

?>